/*
	File:		EntityController_Human.h
	Author:		dmonroe
	Date:		1/12/2012
	Copyright:	Full Sail University

	Purpose:	Human controller for generic CEntity objects
*/

#include "../source/EntityController_Human.h"
#include "../source/Entity.h"

#include "../source/IInput.h"

#include <cassert>


//******************************************************************
// CONSTRUCTOR
CEntityController_Human::CEntityController_Human(void)
{
	m_nKeys[ E_EACT_MOVE_LEFT	] = IInput::E_DPAD_LEFT;
	m_nKeys[ E_EACT_MOVE_RIGHT	] = IInput::E_DPAD_RIGHT;
	m_nKeys[ E_EACT_MOVE_DOWN	] = IInput::E_DPAD_DOWN;
	m_nKeys[ E_EACT_MOVE_UP		] = IInput::E_DPAD_UP;

	m_fActions[ E_EACT_MOVE_LEFT	] = 0.0f;
	m_fActions[ E_EACT_MOVE_RIGHT	] = 0.0f;
	m_fActions[ E_EACT_MOVE_DOWN	] = 0.0f;
	m_fActions[ E_EACT_MOVE_UP		] = 0.0f;

	m_bPerformAction = false;
}
//******************************************************************



//******************************************************************
// 
CEntityController_Human::~CEntityController_Human(void)
{
}
//******************************************************************



//******************************************************************
// 
/*virtual*/ bool	CEntityController_Human::Update				( const CEntity* pEntity, float fElapsedTime )
{
	(void)pEntity;		// ignored - used for fleet maneuvers
	(void)fElapsedTime;	// ignored


	m_bPerformAction = false;

	// Check keys
	IInput* pInput = IInput::GetInstance();

	for( int i = 0; i < 4; i++ )
	{
		if( pInput->IsButtonDown( (IInput::EButton)(m_nKeys[ i ]) ) == true )
		{
			m_fActions[ i ] = 1.0f;
			m_bPerformAction = true;
		}
		else
			m_fActions[ i ] = 0.0f;
	}

	return true;
}
//******************************************************************



//******************************************************************
// 
/*virtual*/ bool	CEntityController_Human::ShouldPerform		( const CEntity* pEntity )
{
	(void)pEntity;		// ignored - used for fleet maneuvers
	return m_bPerformAction;
}
//******************************************************************



//******************************************************************
// 
/*virtual*/ float	CEntityController_Human::ShouldPerformAction	( const CEntity* pEntity, unsigned long ulActionID )
{
	(void)pEntity;		// ignored - used for fleet maneuvers

	switch( ulActionID )
	{
	case E_EACT_MOVE_LEFT:
	case E_EACT_MOVE_RIGHT:
	case E_EACT_MOVE_UP:
	case E_EACT_MOVE_DOWN:
		return m_fActions[ ulActionID ];

	default:
		;	// unknown
	}

	return 0.0f;
}
//******************************************************************



//******************************************************************
// BIND ACTION
void	CEntityController_Human::BindAction( EEntityAction nAction, int nButton )
{
	assert( nAction >= 0 && nAction < 4 && "CEntityController_Human::BindAction - unknown action!" != 0 );
	
	m_nKeys[ nAction ] = nButton;
}
//******************************************************************


